<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"/>

<title>晨阳水漆18周年送红包</title>

<script src="lib/easeljs-0.8.0.min.js"></script>
<script src="lib/tweenjs-0.6.0.min.js"></script>
<script src="lib/movieclip-0.8.0.min.js"></script>
<script src="lib/preloadjs-0.6.0.min.js"></script>
<script src="lib/wx-funding.js"></script>
<script src="makePhoto.js?r=20160503-5"></script>


<script src="lib/binaryajax.js"></script>
<script src="lib/exif.js"></script>
<script src="lib/canvasResize.js"></script>
<script src="lib/jquery.min.js"></script>
<!-- 统计 -->
<script>
    var _hmt = _hmt || [];
    (function() {
        var hm = document.createElement("script");
        hm.src = "//hm.baidu.com/hm.js?9a3730949ba72d60c8429005605b667d";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
</script>


<script>
var canvas, stage, exportRoot;
var count = 0;//loading百分比
var tipsTxt;//提示文本
var manifest, images;//图片加载列表
var isWap;
var loadingMc, loadingText;
var main = null;
var shareTips = null;
var pop = null;
var page,oldpage;
var audio_bg;
var firstPlay=true;

//授权相关变量
var openid, openid_md5, nickname, sex, province, city, country, headimgurl,friendname,friendheadimg;
var appname = 'makePhoto';//当前项目唯一标识，用来区分不同项目的cookie

//存储用户信息
var returnCustomerObj;
var returnWinningList, returnPrizeObj;

//分享相关
var shareLink = location.href;
var shareImg = 'http://weixin.chenyang.com/weixin/2016_makePhoto/h5/images/wxShare.jpg';
var shareTitle = '晨阳水漆18周年庆 为你包了一个红包';
var shareDesc = '大牌崛起，名扬中华';


var uploadimgbitmap = null;
var imgpath;//朋友分享的图片地址
var upload_img_url;//上传的图片地址
var lottery_avaliable=false;//是否可以抽奖

var wxChooseImage=false;//是否使用微信jsskd上传图片
var testNow = false;


//入口函数
function init() {
    iniUiScale();
    GetFriendInfo();
    if (testNow) {
        openid='bbb';
        openid_md5='395c2e9f62556a8fd4e04f8cda392ed1';
        nickname='小明';
        sex='1';
        province='北京';
        city='北京';
        country='CN';
        headimgurl='http://wx.qlogo.cn/mmopen/BA8GZZ2EGwVckE3zlfIdkibgctJ22eS2fWYoB4rzNvV4rpFSLPQtRkOdhGcKPLDdkOEqbcxk2WOq5ofmVHqEaIw/0';

        initCustomer();
        //initCjs();//测试使用
    } else {
        iniLogin();
    }
}

//授权，根据来路显示相应的界面
function iniLogin() {
    //alert(document.location.href);
    readInfo();
    if (openid != null) {
        //已经获得授权
        initCustomer();
    } else {
        //未授权
        //自动跳转到授权页面
        if (imgpath) {
            location.href='getopenid.php?gotourl=index.html&state='+appname+'&imgpath='+imgpath+'&friendname='+friendname+'&friendheadimg='+friendheadimg;
        }else{
            location.href='getopenid.php?gotourl=index.html&state='+appname;
        }
    }
}
//读取本地存储的用户信息，跳转到对应的画面
function readInfo() {
    openid = getCookie(appname + "_openid");
    openid_md5 = getCookie(appname + "_openid_md5");
    nickname = decodeURI(getCookie(appname + "_nickname"));
    sex = decodeURI(getCookie(appname + "_sex"));
    province = decodeURI(getCookie(appname + "_province"));
    city = decodeURI(getCookie(appname + "_city"));
    country = decodeURI(getCookie(appname + "_country"));
    headimgurl = decodeURIComponent(decodeURI(getCookie(appname + "_headimgurl")));
    if (String(headimgurl).indexOf('http') >= 0) {
        //shareImg=headimgurl;
    }
}
//删除cookie
function delInfo() {
    delCookie(appname + "_openid");
    delCookie(appname + "_openid_md5");
    delCookie(appname + "_nickname");
    delCookie(appname + "_sex");
    delCookie(appname + "_province");
    delCookie(appname + "_city");
    delCookie(appname + "_country");
    delCookie(appname + "_headimgurl");
    alert('cookies清除成功');
}
//读取地址栏参数，存入变量中
function GetFriendInfo(){
    //alert(location.href);
    if (GetHashString('imgpath')) {
        imgpath=decodeURIComponent(GetHashString('imgpath'));
        friendname=decodeURI(GetHashString('friendname'));
        friendheadimg=decodeURIComponent(GetHashString('friendheadimg'));
        console.log(imgpath,friendname,friendheadimg);
        location.hash = '';//清空分享的图片地址
    }
    if(GetHashString('state')=='makePhoto'){
        testNow=true;
        openid = GetHashString('openid');
        openid_md5 = GetHashString('openid_md5');
        nickname = decodeURI(GetHashString('nickname'));
        sex = decodeURI(GetHashString('sex'));
        province = decodeURI(GetHashString('province'));
        city = decodeURI(GetHashString('city'));
        country = decodeURI(GetHashString('country'));
        headimgurl = decodeURIComponent(decodeURI(GetHashString('headimgurl')));
        if (String(headimgurl).indexOf('http') >= 0) {
            //shareImg=headimgurl;
        }
        console.log('openid='+openid+'\nopenid_md5='+openid_md5+'\nnickname='+nickname+'\nsex='+sex+'\nprovince='+province+'\ncity='+city+'\ncountry='+country+'\nheadimgurl'+headimgurl);
    }
}

function iniBgSound() {
    var btnsound = new lib.BtnSound();
    btnsound.x = 570;
    btnsound.y = 10;
    btnsound.name='btn_audio_bg';
    stage.addChild(btnsound);
    btnsound.addEventListener('click', soundClickHandle);

    audio_bg = getEl('music_audio_bg');
    audio_bg.play();
    if (window.WeixinJSBridge) {
        WeixinJSBridge.invoke('getNetworkType', {}, function (e) {
            //alert('自动播放');
            if (firstPlay && audio_bg.currentTime == 0) {
                audio_bg.play();
                //main.btn_sound.visible=true;
                firstPlay = false;
            }
        });
    } else {
        document.addEventListener("WeixinJSBridgeReady", function () {
            WeixinJSBridge.invoke('getNetworkType', {}, function (e) {
                //alert('自动播放');
                if (firstPlay && audio_bg.currentTime == 0) {
                    audio_bg.play();
                    //main.btn_sound.visible=true;
                    firstPlay = false;
                }
            });
        }, false);

    }

    //背景音乐开关
    function soundClickHandle(evt) {
        if (checkPointID(evt)) {
            if (evt.currentTarget.currentFrame == 0) {
                evt.currentTarget.gotoAndStop(1);
                audio_bg.pause();
            } else {
                evt.currentTarget.gotoAndStop(0);
                audio_bg.play();
            }
        }
    }
}
//框架代码--------
function initCjs() {
    //audio_bg=getEl('music_audio_bg');
    //stageH = (640 / document.documentElement.clientWidth) * document.documentElement.clientHeight;
    canvas = getEl('mainCanvas');
    stage = new createjs.Stage(canvas);
    exportRoot = new lib.makePhoto();
    stage.addChild(exportRoot);
    stage.update();
    stage.enableMouseOver();

    createjs.Ticker.setFPS(lib.properties.fps);
    createjs.Ticker.addEventListener('tick', stage);
    preloading();
    //iniFps();
    iniWx();
}
//预载loading界面
function preloading() {
    //alert('预载');
    manifest = [
        {src:"images/bg.jpg", id:"bg"},
        {src:"images/home4.png", id:"home4"}
    ];

    var loader = new createjs.LoadQueue(false);
    //loader.installPlugin(createjs.Sound);
    loader.addEventListener('fileload', preloadingHandleFileLoad);
    loader.addEventListener('complete', preloadingHandleComplete);
    loader.loadManifest(manifest);
}
function preloadingHandleFileLoad(evt) {
    if (evt.item.type == 'image') {
        images[evt.item.id] = evt.result;
    }
}
function preloadingHandleComplete() {
    loading();
}
//loading
function loading() {
    loadingMc = new lib.LoadingMc();
    loadingMc.x = 0;
    exportRoot.addChild(loadingMc);

    images = images || {};
    var loader = new createjs.LoadQueue(false);
    //loader.installPlugin(createjs.Sound);
    loader.addEventListener('fileload', handleFileLoad);
    loader.addEventListener('complete', handleComplete);
    //loader.loadFile({src:"images/ShuangDan_atlas_.json", type:"spritesheet", id:"ShuangDan_atlas_"}, true);
    loader.loadManifest(lib.properties.manifest);
}
function handleFileLoad(evt) {
    if (evt.item.type == 'image') {
        images[evt.item.id] = evt.result;
    }
    count++;
    loadingMc.msg.text ='Loading '+(Math.floor(count / lib.properties.manifest.length * 100))+'%';
    //loadingMc.bar.gotoAndStop(Math.floor(count / lib.properties.manifest.length * 100) - 1);
}

function handleComplete(evt) {
    iniHome();
    iniBgSound();
}

//初始化首页-------
function iniHome() {
    checkDevice();
    iniEvent();
    //清除loading
    exportRoot.removeChild(loadingMc);
    loadingMc = null;
    //console.log(imgpath);
    if(imgpath){
        iniFriendPhotoMc();
    }else{
        iniMainMc();
    }
}
function iniEvent() {
    if (createjs.Touch.isSupported()) {
        createjs.Touch.enable(stage);
    }
    //stage.addEventListener("stagemousedown", stagemousedownHandle);
}

//显示fps
function iniFps() {
    var fpsLabel = new createjs.Text("-- fps", "bold 18px Arial", "#ccc");
    stage.addChild(fpsLabel);
    fpsLabel.x = 10;
    fpsLabel.y = 20;
    fpsLabel.visible = true;
    fpsLabel.addEventListener('tick', fpsEnterFrameHandle);
    function fpsEnterFrameHandle(evt) {
        fpsLabel.text = Math.round(createjs.Ticker.getMeasuredFPS()) + " fps";
    }
}
//---------界面---------
function iniMainMc(){
    if (main != null) {
        exportRoot.removeChild(main);
        main = null;
    }
    main = new lib.HomeMc();
    exportRoot.addChild(main);
    main.gotoAndPlay(1);
    main.btn_play.addEventListener('mousedown',btnMousedownHandle);
    main.btn_play.addEventListener('pressup',playUpHandle);
    main.btn_rule.addEventListener('mousedown',btnMousedownHandle);
    main.btn_rule.addEventListener('pressup',ruleUpHandle);
}
//上传照片界面---
function iniPhotoMc(){
    if (main != null) {
        exportRoot.removeChild(main);
        main = null;
    }
    main = new lib.PhotoMc();
    exportRoot.addChild(main);
    main.gotoAndPlay(1);
    main.btn_reupload.visile=false;
    main.btn_save.visile=false;
    main.loading_tips.visible=false;

    main.btn_save.addEventListener('mousedown',btnMousedownHandle);
    main.btn_save.addEventListener('pressup',saveUpHandle);
    main.btn_reupload.addEventListener('mousedown',btnMousedownHandle);
    main.btn_reupload.addEventListener('pressup',reuploadUpHandle);
    //main.btn_show.addEventListener('mousedown',btnMousedownHandle);
    //main.btn_show.addEventListener('pressup',showUpHandle);
    main.btn_share.addEventListener('mousedown',btnMousedownHandle);
    main.btn_share.addEventListener('pressup',shareUpHandle);

    if(wxChooseImage){
        //使用微信jsskd上传图片
        main.btn_upload.addEventListener('mousedown',btnMousedownHandle);
        main.btn_upload.addEventListener('pressup',photoUpHandle);
    }else{
        iniPhotoUpload();
    }
    iniPage(main.upload);
}
//初始化上传框
function iniPhotoUpload() {
    getEl('upload_btn').addEventListener('change', uploadHandle);
    getEl('upload_btn').style.display = 'block';
}
//初始化拍照场景
function iniPage(con){
    page=eval('new lib.Page1()');
    con.addChild(page);
    page.gotoAndPlay(1);
    stage.addEventListener("stagemousedown",stagemousedownHandle);
}
function nextPage(id,con){
    if(id>=1 && id<=7){
        oldpage=page;
        createjs.Tween.get(oldpage).to({x:-640}, 500).call(removePage);
        console.log('new lib.Page'+id+'()');
        page=eval('new lib.Page'+id+'()');
        page.x=640;
        con.addChild(page);
        createjs.Tween.get(page).to({x:0}, 500).call(playPage);
        if(id==7){
            getEl('write_txt').style.display='block';
        }else{
            getEl('write_txt').style.display='none';
        }
    }
}
//上一页
function prePage(id,con){
    if(id>=1){
        oldpage=page;
        createjs.Tween.get(oldpage).to({x:640}, 500).call(removePage);
        console.log('new lib.Page'+id+'()');
        page=eval('new lib.Page'+id+'()');
        page.x=-640;
        con.addChild(page);
        createjs.Tween.get(page).to({x:0}, 500).call(playPage);
        if(id==7){
            getEl('write_txt').style.display='block';
        }else{
            getEl('write_txt').style.display='none';
        }
    }
}

function removePage(){
    main.upload.removeChild(oldpage);
    oldpage=null;
}
function playPage(){
    page.gotoAndPlay(1);
}
//左右切换--------
var iniX,tempX,iniTime,nowTime;
var currentP=1;
function stagemousedownHandle(event){
    event.preventDefault();
    iniX=event.stageX;
    tempX=event.stageX;
    iniTime=new Date().getTime();
    stage.addEventListener("stagemouseup",stagemouseupHandle);
}

function stagemouseupHandle(event){
    event.preventDefault();

    nowTime=new Date().getTime();
    if(event.stageX>iniX && (event.stageX>iniX+200 || (nowTime-iniTime)<500)){
        //判断用户是否向下移动了足够远
        if(currentP>1) {
            currentP--;
            console.log(currentP);
            prePage(currentP,main.upload);
            //stage.removeEventListener("stagemousedown",stagemousedownHandle);
        }else{
            currentP=7;
            console.log(currentP);
            prePage(currentP,main.upload);
        }
    }
    if(event.stageX<iniX && (event.stageX<iniX-200 || (nowTime-iniTime)<500)){
        //判断用户是否向上移动了足够远
        if(currentP<7) {
            currentP++;
            console.log('currentP=' + currentP);
            nextPage(currentP,main.upload);
            //stage.removeEventListener("stagemousedown",stagemousedownHandle);
        }else{
            currentP=1;
            console.log('currentP=' + currentP);
            nextPage(currentP,main.upload);
        }
    }

    iniX=event.stageX;
    tempX=event.stageX;
    iniTime=new Date().getTime();

    stage.removeEventListener("stagemouseup",stagemouseupHandle);
}
//活动规则界面---
function iniRuleMc(){
    if (pop != null) {
        exportRoot.removeChild(pop);
        pop = null;
    }
    pop = new lib.RuleMc();
    exportRoot.addChild(pop);
    pop.gotoAndPlay(1);
    pop.btn_back.addEventListener('mousedown',btnMousedownHandle);
    pop.btn_back.addEventListener('pressup',backUpHandle);
}
//抽奖界面---
function iniLuckMc(){
    getEl('uploadBox_btn').style.display = 'none';
    getEl('share').style.display='none';
    if (main != null) {
        exportRoot.removeChild(main);
        main = null;
    }
    main = new lib.LuckMc();
    exportRoot.addChild(main);
    main.gotoAndPlay(1);
    main.btn_luck.addEventListener('mousedown',btnMousedownHandle);
    main.btn_luck.addEventListener('pressup',luckUpHandle);
}
//显示奖品界面----
function iniPrizeMc(gift_type){
    var title,msg;
    if(gift_type==0){
        alertMsg('很遗憾，未中奖!');
    }else{
        if (main != null) {
            exportRoot.removeChild(main);
            main = null;
        }
        main = new lib.PrizeMc();
        //处理中奖结果
        if(gift_type>=1 && gift_type<=7){
            switch(gift_type){
                case 1:
                    //手机
                    title='一等奖';
                    msg='获得华为P9手机';
                    main.prize_con.prize_1.visible=true;
                    break;
                case 2:
                    //相机
                    title='二等奖';
                    msg='获得富士趣奇拍立得照相机';
                    main.prize_con.prize_2.visible=true;
                    break;
                case 7:
                    //优惠券
                    title='鼓励奖';
                    msg='截屏保存优惠码，\n进入晨阳水漆天猫旗舰店购物，\n将截图发送给客服即可使用。';
                    main.prize_con.prize_4.visible=true;
                    main.prize_con.prize_4.msg.text=returnPrizeObj.gift_code;
                    main.btn_write.visible=false;
                    main.prize_con.prize_4.hit_link.addEventListener('click',linkUpHandle);
                    break;
                default :
                    //case 3,4,5,6:
                    title='三等奖';
                    msg='获得'+returnPrizeObj.money+'元现金红包奖品，\n已经发放到您的微信钱包，\n请注意查收。';
                    main.prize_con.prize_3.visible=true;
                    main.prize_con.prize_3.msg.text=returnPrizeObj.money+'元';
                    main.btn_write.visible=false;
                    break;
            }
        }

        main.prize_title.msg.text=title;
        main.msg.text=msg;
        exportRoot.addChild(main);
        main.gotoAndPlay(1);
        main.btn_write.addEventListener('mousedown',btnMousedownHandle);
        main.btn_write.addEventListener('pressup',writeUpHandle);
        main.hit_fans.addEventListener('click',fansClickHandle);
    }
}
//显示朋友分享界面
function iniFriendPhotoMc(){
    if (main != null) {
        exportRoot.removeChild(main);
        main = null;
    }
    main = new lib.FriendPhotoMc();
    exportRoot.addChild(main);

    main.msg.text='您的朋友'+friendname+'\n参与晨阳水漆18周年送红包活动中奖了！';
    loadingOneImg([{'src':imgpath,'id':'loadOneImg'}],function(img_src){
        var w, h,b;
        var bitmap=new createjs.Bitmap(img_src);
        b=bitmap.getBounds();
        main.img_loader.addChild(bitmap);
        main.gotoAndPlay(1);
    });
    main.btn_begin.addEventListener('mousedown',btnMousedownHandle);
    main.btn_begin.addEventListener('pressup',beginUpHandle);
}
//loading单个图片n------------------
function loadingOneImg(arr, callback) {
    var loader = new createjs.LoadQueue(false);
    loader.addEventListener('fileload', loadingOneImgResFileLoad);
    loader.addEventListener('complete', loadingOneImgResComplete);
    loader.loadManifest(arr);
    function loadingOneImgResFileLoad(evt) {
        console.log('loading now');
    }

    function loadingOneImgResComplete(evt) {
        callback(evt.currentTarget.getResult('loadOneImg').src);
    }
}
//------------------------------事件------------------------
//分享按钮事件
function shareUpHandle(evt) {
    if (checkPointID(evt)) {
        createjs.Tween.get(evt.currentTarget).to({scaleX: 1, scaleY: 1}, 200).call(showShare);
    }
}

//公用按钮按下事件
function btnMousedownHandle(evt) {
    if (checkPointID(evt)) {
        createjs.Tween.get(evt.currentTarget).to({scaleX: 0.9, scaleY: 0.9}, 100);
    }
}
//开始按钮事件
function playUpHandle(evt) {
    if (checkPointID(evt)) {
        createjs.Tween.get(evt.currentTarget).to({scaleX: 1, scaleY: 1}, 100).call(iniPhotoMc);
    }
}
//活动规则事件
function ruleUpHandle(evt) {
    if (checkPointID(evt)) {
        createjs.Tween.get(evt.currentTarget).to({scaleX: 1, scaleY: 1}, 100).call(iniRuleMc);
        //delInfo();//test
    }
}
//上传图片按钮事件
function photoUpHandle(evt){
    if(checkPointID(evt)){
        createjs.Tween.get(evt.currentTarget).to({scaleX: 1, scaleY: 1}, 200).call(function(){
            if(wx){
                chooseImage();
            }
        });
    }
}
//保存图片事件
function saveUpHandle(evt){
    if (checkPointID(evt)) {
        createjs.Tween.get(evt.currentTarget).to({scaleX: 1, scaleY: 1}, 100).call(function(){
            getEl('uploadBox_btn').style.display = 'none';
            stage.removeEventListener("stagemousedown",stagemousedownHandle);

            var myDate = new Date();
            var timeLabel = new createjs.Text(formatDate(myDate), "bold 18px Arial", "#000");
            main.upload.addChild(timeLabel);
            timeLabel.x = 10;
            timeLabel.y = 1020;
            main.upload.cache(0, 0, 640, 1050);
            if(wxChooseImage){
                submitGameData(encodeURIComponent(main.upload.cacheCanvas.toDataURL("image/jpeg")));
            }else{
                submitGameData(encodeURIComponent(main.upload.cacheCanvas.toDataURL("image/jpeg",0.6)));
            }

            //设置预览图
            //getEl('upload_img').src=main.upload.cacheCanvas.toDataURL("image/jpeg");
            //submitGameData(encodeURIComponent(main.upload.cacheCanvas.toDataURL("image/jpeg")));
            //getEl('upload_img').src=main.upload.getCacheDataURL();
            //submitGameData(encodeURIComponent(main.upload.getCacheDataURL()));
        });
    }
}
//重新上传事件
function reuploadUpHandle(evt){
    if (checkPointID(evt)) {
        createjs.Tween.get(evt.currentTarget).to({scaleX: 1, scaleY: 1}, 100).call(function(){
            main.btn_upload.visible=true;
            if(!wxChooseImage){
                getEl('upload_btn').style.display = 'block';
            }
        });
    }
}
//存图自己看
function showUpHandle(evt){
    if (checkPointID(evt)) {
        createjs.Tween.get(evt.currentTarget).to({scaleX: 1, scaleY: 1}, 100).call(function(){
            //显示预览图
            getEl('view_upload_img').style.display='block';
        });
    }
}
//规则返回事件
function backUpHandle(evt){
    if (checkPointID(evt)) {
        createjs.Tween.get(evt.currentTarget).to({scaleX: 1, scaleY: 1}, 100).call(function(){
            if(pop){
                exportRoot.removeChild(pop);
                pop=null;
            }
        });
    }
}
//抽奖按钮
function luckUpHandle(evt){
    if (checkPointID(evt)) {
        createjs.Tween.get(evt.currentTarget).to({scaleX: 1, scaleY: 1}, 100).call(function(){
            if(main){
                main.luck_movie.gotoAndPlay(1);
            }
            iniTime=new Date().getTime();
            drawnLottery();
        });
    }
}
//填信息
function writeUpHandle(evt){
    if (checkPointID(evt)) {
        createjs.Tween.get(evt.currentTarget).to({scaleX: 1, scaleY: 1}, 100).call(function(){
            getEl('infoForm').style.display='block';
            iniMainMc();
        });
    }
}
//分享
function showShare() {
    getEl('share').style.display = 'block';
}
//链接
function linkUpHandle(evt) {
    if (checkPointID(evt)) {
        location.href = 'http://cysq.tmall.com';
    }
}
//关注
function fansClickHandle(evt){
    if (checkPointID(evt)) {
        location.href = 'http://mp.weixin.qq.com/mp/appmsg/show?__biz=MjM5NTA3Nzc2MA==&appmsgid=10000027&itemidx=1&sign=8c44b0abf1ffea4193fdb7097f93a857#wechat_redirect';
    }
}
//开始
function beginUpHandle(evt){
    if (checkPointID(evt)) {
        createjs.Tween.get(evt.currentTarget).to({scaleX: 1, scaleY: 1}, 100).call(function(){
            iniMainMc();
        });
    }
}
//-----------------后台接口------------
//存储用户信息
function initCustomer() {
    var params = [];
    params.push('openid='+openid);
    params.push('openid_md5='+openid_md5);
    params.push('nickname='+nickname);
    params.push('sex='+sex);
    params.push('province='+province);
    params.push('city='+city);
    params.push('country='+country);
    params.push('headimgurl='+headimgurl);
    //alert(params);
    sendRequest('http://weixin.chenyang.com/weixin/2016_makePhoto/api_chenyang_make_photo/initCustomer',function(res){
        //alert(res.response);
        res = eval('('+res.response+')');
        if(res.success) {
            //location.reload();
            lottery_avaliable=res.addon.lottery_avaliable;
            returnCustomerObj=res.addon.customer;
            console.log(returnCustomerObj,lottery_avaliable);
            if(returnCustomerObj.customer_name!=''){
                getEl('customer_name').value=returnCustomerObj.customer_name;
                getEl('customer_phone').value=returnCustomerObj.customer_phone;
                getEl('customer_address').value=returnCustomerObj.customer_address;
                //getEl('infoForm').style.display='block';
            }
            initCjs();
            //alert('信息存储成功='+returnCustomerObj);
        }else{
            alertMsg(res.detail);
            initCjs();
        }
    },params.join('&'));
}
//保存图片
function submitGameData(upload_image){
    //显示loading
    main.loading_tips.visible=true;
    var params = [];
    //params.push('openid='+openid);
    //params.push('openid_md5='+openid_md5);
    params.push('img_base64='+upload_image);

    //console.log(params);
    sendRequest('http://weixin.chenyang.com/weixin/2016_makePhoto/api_chenyang_make_photo/submitPhoto',function(res){
        //alert(res.response);
        res = eval('('+res.response+')');
        if(res.success) {
            upload_img_url=res.addon.img_url;
            //当图片上传完之后，重置预览图
            getEl('upload_img').src=upload_img_url;
            //修改分享
            location.hash = '#imgpath=' + upload_img_url +'&friendname=' + encodeURI(encodeURI(nickname)) +'&friendheadimg=' + headimgurl;
            //prompt('url',location.href);
            shareLink = location.href;
            shareImg=upload_img_url;
            //shareTitle = '晨阳水漆18周年送红包';
            iniWx();
            //图片上传成功后，继续动画
            main.loading_tips.visible=false;
            main.gotoAndPlay('show');
        }else{
            alertMsg(res.detail);
            //如果上传错误，隐藏上传loading
            main.loading_tips.visible=false;
        }
    },params.join('&'));
}
//抽奖
function drawnLottery(){
    var params = [];
    //params.push('openid='+openid);
    //params.push('openid_md5='+openid_md5);
    //alert(params);
    sendRequest('http://weixin.chenyang.com/weixin/2016_makePhoto/api_chenyang_make_photo/drawnLottery',function(res){
        //alert(res.response);
        res = eval('('+res.response+')');
        if(res.success) {
            console.log(res);
            returnPrizeObj=res.addon;
            //停止抽奖效果
            nowTime=new Date().getTime();
            if((nowTime-iniTime)>2000){
                setTimeout(function(){
                    main.luck_movie.stop();
                    iniPrizeMc(parseInt(returnPrizeObj.gift_type));
                },1000)
            }else{
                setTimeout(function(){
                    main.luck_movie.stop();
                    iniPrizeMc(parseInt(returnPrizeObj.gift_type));
                },2000);
            }
        }else{
            alertMsg(res.detail);
            main.luck_movie.stop();
        }
    },params.join('&'));
}
//提交个人信息
function submitForm(frm) {
    var params = [];
    var email_reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
    for(var i=0,len = frm.elements.length; i < len; i++) {
        el = frm.elements[i];
        if(el.name=='customer_name' && el.value=='') {
            alertMsg('请输入你的姓名!');
            return false;
        }
        if(el.name=='customer_phone' && !(/^1(3|5|8)\d{9}$/.test(el.value))) {
            alertMsg('请输入正确的手机号码!');
            return false;
        }
        if(el.name=='customer_address' && el.value=='') {
            alertMsg('请输入正确的收货地址!');
            return false;
        }
        if(el.name && el.value !== '' && (el.type !='radio' || el.checked)) {
            params.push(el.name +'='+ el.value);
        }
    }
    console.log(params);
    sendRequest(frm.action,function(res){
        res = eval('('+res.response+')');
        //alert(res.detail);
        if(res.success) {
            alertMsg('信息提交成功');
            setTimeout(function(){getEl('infoForm').style.display='none';},3000);
        }else{
            alertMsg(res.detail);
        }
    },params.join('&'));
}

//----------终端检测------
function checkDevice() {
    if (!navigator.userAgent.match(/mobile/i)) {
        //alert("当前设备为pc");
        isWap = false;
    } else {
        //alert("当前设备为移动");
        isWap = true;
    }
}
function checkPointID(evt) {
    if (isWap) {
        if (evt.pointerID != -1) {
            return true;
        } else {
            return false;
        }
    } else {
        if (evt.pointerID == -1) {
            return true;
        } else {
            return false;
        }
    }
}

//控制ui自适应
function iniUiScale() {
    var p = document.documentElement.clientWidth / 640;
    getEl('share').style.zoom = p;
    getEl('uploadBox_btn').style.zoom = p;
    getEl('tips').style.zoom = p;
    getEl('view_upload_img').style.zoom = p;
    getEl('infoForm').style.zoom = p;
}


//图片上传
function uploadHandle(evt) {
    var files;
    files = this.files;
    if (files.length > 0) {
        handleLocalFile(files[0]);
    }
}
//处理上传的图片
function handleLocalFile(file) {
    canvasResize(file, {
        width: 1920,
        height: 1050,
        crop: false,
        quality: 80,
        rotate: 0,
        callback: function (data, width, height) {
            //encodeURIComponent(data)
            console.log(width,height);
            uploadimgbitmap = new createjs.Bitmap(data);
            if(width/height > 640/1050){
                //宽高比大于屏幕，适配高度即可
                uploadimgbitmap.scaleX=uploadimgbitmap.scaleY=1050/height;
                uploadimgbitmap.x=-(width*(1050/height)-640)/2;
            }else{
                //宽市区比小于屏幕，适配宽度
                uploadimgbitmap.scaleX=uploadimgbitmap.scaleY=640/width;
                uploadimgbitmap.y=-(height*(640/width)-1050)/2;
            }
            main.upload.img_loader.removeAllChildren();
            main.upload.img_loader.addChild(uploadimgbitmap);
            main.btn_reupload.visible=true;
            main.btn_save.visible=true;
            main.btn_upload.visible=false;
            getEl('upload_btn').style.display = 'none';
        }
    });
}


//显示提示文本
function alertMsg(msg){
    getEl('msg').innerHTML=msg;
    addClass(getEl('tips'), 'show');
}
function closeMsg(){
    removeClass(getEl('tips'), 'show');
}

//格式化日期
function formatDate(now) {
    var year=now.getFullYear();
    var month=now.getMonth()+1;
    var date=now.getDate();
    var hour=now.getHours();
    var minute=now.getMinutes();
    var second=now.getSeconds();
    if(hour<=12){
        hour="AM" +hour;
    }else if(hour>12 && hour<18){
        hour-=12;
        hour="FM" +hour;
    }else if(hour>=18 && hour<23){
        hour-=12;
        hour="FM" +hour;
    }
    return year+"."+month+"."+date+" "+hour+":"+minute;
}

function txtLength(str) {
    var len = 0;
    var arr=str.split('');
    for (var i = 0; i < str.length; i++) {
        var c = str.charCodeAt(i);
        //单字节加1
        if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
            len++;
        }
        else {
            len += 2;
        }
    }
    return len;
}
</script>

<style>
    html, body {
        width: 100%;
        height: 100%;
        overflow: hidden;
        font-family: arial, "Hiragino Sans GB", "Microsoft Yahei", sans-serif;
    }

    body {
        margin: 0px;
        padding: 0px;
    }

    #mainCanvas {
        position: absolute;
        left: 0;
        top: 0;
        z-index: 2;
        width: 100%;
        height: 100%;
        display: inline-block;
    }

    p, span, a, dl, dt, dd, ul, li, input, form {
        margin: 0;
        padding: 0;
        list-style: none;
    }

    /*uploadBox*/
    .uploadBox_btn {
        position: absolute;
        z-index: 10;
        left: 0px;
        top: 0px;
        width: 1px;
        height: 100%;
        display: block;
    }

    .uploadBox_btn input.upload_btn {
        position: absolute;
        display: none;
        opacity: 0;
        width: 245px;
        height: 30%;
        left:198px;
        top:15%;
        background: #ff0000;
    }
    .uploadBox_btn input.write_txt {
        position: absolute;
        display: none;
        opacity: 0;
        width: 350px;
        height: 5%;
        left:210px;
        bottom:20%;
        background: #ff0000;
        font-size: 240%;
    }
    /*share*/
    .share {
        position: absolute;
        z-index: 101;
        width: 640px;
        height: 1200px;
        background-color: rgba(0, 0, 0, 0.8);
        text-align: right;
        display: none;
    }

    .share a {
        display: block;
        width: 100%;
        height: 100%;
    }

    .hide {
        opacity: 0;
        transition: all 1s;
        -moz-transition: all 1s;
    }

    /*tips*/
    .tips{
        position: absolute;
        top:0;
        left:0;
        z-index: 999;
        width:100%;
        height: 100%;
        background: rgba(0,0,0,0.5);
        display: none;
    }
    .show{
        display: block;
    }
    .tips .con{
        position: absolute;
        left:10%;
        top: 40%;
        width:80%;
        height: auto;
        border-radius: 5px;
        background: #242f51;
        color: #fff;
        text-align: center;
    }
    .tips .con .msg{
        padding: 30px 20px;
        font-size: 150%;
        border-bottom: 1px solid #2f3a5b;
    }
    .tips .con .btn{

    }
    .tips .con .btn a{
        display: block;
        padding: 20px 0px;
        font-size: 130%;
        text-decoration:none;
        color: #fff;
    }
    /*view_upload_img*/
    .view_upload_img{
        position: absolute;
        top:0;
        left:0;
        z-index: 998;
        width:100%;
        height: 100%;
        background: rgba(0,0,0,1);
        display: none;
        text-align: center;
        color: #fff;
    }
    .view_upload_img img{
        width:80%;
        height: auto;
        margin-top: 10%;
    }
    .view_upload_img a.btn{
        position: absolute;
        right: 20px;
        top:30px;
        display: block;
        width:70px;
        height: 70px;
        line-height: 70px;
        color:#fff;
        font-size:300%;
        border-radius: 25px;
        border: 1px solid #fff;
        text-decoration: none;
        font-family: arial, "Hiragino Sans GB", "Microsoft Yahei", sans-serif;
        background: rgba(0,0,0,0.5);
    }
    .view_upload_img p{
        font-size: 150%;
        margin-top: 20px;
    }
    /*inforForm*/
    .infoForm {
        position: absolute;
        left: 0;
        bottom: 0;
        z-index: 4;
        width: 640px;
        height: 100%;
        text-align: center;
        color: #fff;
        display: none;
        background: url('images/bg.jpg') no-repeat;
        background-size: cover;
    }
    .infoForm .infoFormBd{
        width:488px;
        height: 100%;
        margin: 0 auto;
        margin-top: 30%;
    }
    .infoForm form {
        width: 100%;
        margin: 0 auto;
    }

    .infoForm input {
        display: block;
        width: 100%;
        height: 80px;
        line-height: 80px;
        background: rgba(0,0,0,0.7);
        color: #fff;
        margin: 1px auto 0 auto;
        font-size: 150%;
        text-indent: 20px;
        border: none;
    }

    .infoForm form a.btn {
        display: block;
        width:220px;
        height: 70px;
        margin: 0 auto;
        margin-top: 40px;
        -webkit-tap-highlight-color: transparent;
    }
    .infoForm .logo{
        position: absolute;
        left:20px;
        top:20px;
    }

</style>
</head>

<body onload="init();" style="background:#000">

<canvas id="mainCanvas" width="640" height="1050" style="background: transparent;"></canvas>

<!-- 选择图片按钮 -->
<div class="uploadBox_btn" id="uploadBox_btn">
    <input class="upload_btn" id="upload_btn" type="file" name="upload_btn" accept="image/*" capture="camera">
    <input class="write_txt" id="write_txt" type="text" name="write_txt" value="我在" onfocus="page.tips.visible=false;" oninput="if(txtLength(this.value)<=18){page.msg.text=this.value;}else{alertMsg('字数超限');};"/>
</div>

<!-- 分享 -->
<div class="share" id="share">
    <a href="javascript:void(0);" onclick="getEl('share').style.display='none';"><img src="images/share.png"/></a>
</div>
<!-- 提示 -->
<div class="tips" id="tips">
    <div class="con">
        <div class="msg" id="msg">请选择答案</div>
        <div class="btn"><a href="javascript:void(0);" ontouchstart="closeMsg();">关闭</a></div>
    </div>
</div>
<!-- 上传的图片 -->
<div class="view_upload_img" id="view_upload_img">
    <img id="upload_img" src="images/photo.png"/>
    <p>长按图片可保存</p>
    <a class="btn" href="javascript:void(0);" onclick="getEl('view_upload_img').style.display='none';">X</a>
</div>

<!-- 个人信息 -->
<div class="infoForm" id="infoForm">
    <div class="logo"><img src="images/logo.png" /></div>
    <div class="infoFormBd">
        <p style="font-size: 200%; margin-bottom: 30px;">请填写您的领奖信息</p>
        <form action="http://weixin.chenyang.com/weixin/2016_makePhoto/api_chenyang_make_photo/submitAddress" method="POST" id="js_frm_submit2"
              onsubmit="submitForm(this); return false;">
            <input id="customer_name" type="text" name="customer_name" placeholder="请输入姓名" onblur="window.scrollTo(0,0);"/>
            <input id="customer_phone" type="tel" name="customer_phone" placeholder="请输入电话" onblur="window.scrollTo(0,0);"/>
            <input id="customer_address" type="text" name="customer_address" placeholder="请输入地址" onblur="window.scrollTo(0,0);"/>
            <p style="margin-top:20px;">
                <a class="btn" href="javascript:void(0);" onclick="submitForm(getEl('js_frm_submit2'));"><img src="images/btn-submit.png" /></a>
            </p>
        </form>
    </div>
</div>

<!-- 背景音乐显示-->
<div style="display: none">
    <audio id="music_audio_bg" preload="preload" loop="loop" style="display: none;">
        <source src="bgm.mp3" type="audio/mpeg">
    </audio>
</div>

<script type="text/javascript">
    document.body.ontouchmove = function (e) {
        e.preventDefault();
        //window.scrollTo(0,0);
    };
</script>
<!-- 微信jssdk -->
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script src="http://weixin.chenyang.com/weixin/2016_makePhoto/h5/accessToken/signPackage.php"></script>
<script>
    function iniWx() {
        wx.config({
            debug: false,
            appId: signPackage.appId,
            timestamp: parseInt(signPackage.timestamp),
            nonceStr: signPackage.nonceStr,
            signature: signPackage.signature,
            jsApiList: [
                'checkJsApi',
                'onMenuShareTimeline',
                'onMenuShareAppMessage',
                'chooseImage'
            ]
        });
        //config接口处理成功后
        wx.ready(function () {
            // 1 判断当前版本是否支持指定 JS 接口，支持批量判断
            wx.checkJsApi({
                jsApiList: [
                    'getNetworkType',
                    'onMenuShareTimeline',
                    'onMenuShareAppMessage',
                    'chooseImage'
                ],
                success: function (res) {
                    //alert(JSON.stringify(res));
                    //网络+分享
                    checkResult = eval('(' + JSON.stringify(res) + ')');
                    checkResult = checkResult.checkResult;

                    if (checkResult.getNetworkType) {
                        getNetworkType();
                    }
                    if (checkResult.onMenuShareTimeline) {
                        onMenuShareTimeline();
                    }
                    if (checkResult.onMenuShareAppMessage) {
                        onMenuShareAppMessage();
                    }
                }
            });
        });

        //错误
        wx.error(function (res) {
            alert(res.errMsg);
        });
    }
    //------------------------------图像接口-------------------
    function chooseImage(){
        wx.chooseImage({
            count: 1, // 默认9
            sizeType: ['compressed'], // 'original', 'compressed'可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album','camera'], // 'album', 'camera'可以指定来源是相册还是相机，默认二者都有
            success: function (res) {
                getEl('upload_img').src=res.localIds;// 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
                //getEl('view_upload_img').style.display='block';

                var width, height, b;
                uploadimgbitmap=new createjs.Bitmap(getEl('upload_img').src);
                setTimeout(function(){
                    b=uploadimgbitmap.getBounds();
                    //alert(b);
                    width=b.width;
                    height=b.height;

                    if(width/height > 640/1050){
                        //宽高比大于屏幕，适配高度即可
                        uploadimgbitmap.scaleX=uploadimgbitmap.scaleY=1050/height;
                        uploadimgbitmap.x=-(width*(1050/height)-640)/2;
                    }else{
                        //宽市区比小于屏幕，适配宽度
                        uploadimgbitmap.scaleX=uploadimgbitmap.scaleY=640/width;
                        uploadimgbitmap.y=-(height*(640/width)-1050)/2;
                    }
                    main.upload.img_loader.removeAllChildren();
                    main.upload.img_loader.addChild(uploadimgbitmap);
                    main.btn_reupload.visible=true;
                    main.btn_save.visible=true;
                    main.btn_upload.visible=false;

                },300);

            }
        });
    }
    //------------------------------以下为常规接口-------------------------

    //配置检测网络接口
    function getNetworkType() {
        wx.getNetworkType({
            success: function (res) {
                console.log(res.networkType);
            },
            fail: function (res) {
                console.log(JSON.stringify(res));
            }
        });
    }
    //注册获取“发送给朋友”状态事件
    function onMenuShareAppMessage() {
        //location.hash='#openid='+openid+'&openid_md5='+openid_md5+'&nickname='+encodeURI(encodeURI(nickname))+'&sendToLove=yes';//修改发送给朋友链接
        //alert('发送给朋友的链接='+location.href);
        wx.onMenuShareAppMessage({
            title: shareTitle,
            desc: shareDesc,
            link: location.href,
            imgUrl: shareImg,
            trigger: function (res) {
                //alert('用户点击发送给朋友');
            },
            success: function (res) {
                //alert('已分享');
                if(lottery_avaliable){
                    iniLuckMc();
                }else{
                    alertMsg('感谢分享，活动已结束!');
                }
            },
            cancel: function (res) {
                //alert('已取消');
            },
            fail: function (res) {
                //alert(JSON.stringify(res));
            }
        });
    }
    //注册获取“分享到朋友圈”状态事件
    function onMenuShareTimeline() {
        wx.onMenuShareTimeline({
            title: shareTitle,
            link: location.href,
            imgUrl: shareImg,
            trigger: function (res) {
                //alert('用户点击分享到朋友圈');
            },
            success: function (res) {
                //alert('已分享');
                if(lottery_avaliable){
                    iniLuckMc();
                }else{
                    alertMsg('感谢分享，活动已结束!');
                }
            },
            cancel: function (res) {
                //alert('已取消');
            },
            fail: function (res) {
                //alert(JSON.stringify(res));
            }
        });
    }
</script>
</body>

</html>